part of "../framework.dart";

class Pages {
  /// 返回上级页面（路径动画在[navigatorWidget]中定义好了）
  static void back<T>([T? result]) => Navigator.pop(contextNow, result);

  /// 用默认的渐变路径动画跳转页面
  static Future<T?> to<T>(Widget page) async => await Navigator.push(
        contextNow,
        MaterialPageRoute(builder: (context) => page),
      );

  /// 替换：移除页面（但不添加动画）后立刻前往新页面
  static Future<T?> toReplace<T>(Widget page) async =>
      await Navigator.pushReplacement(
        contextNow,
        MaterialPageRoute(builder: (context) => page),
      );

  /// 将所有页面移除后，添加一个页面
  static Future<void> toClear(Widget initPage) async =>
      await Navigator.pushAndRemoveUntil(
        contextNow,
        MaterialPageRoute(builder: (context) => initPage),
        (route) => false,
      );
}
